﻿<Window x:Class="TB4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Collections="clr-namespace:System.Collections;assembly=mscorlib" xmlns:TB4="clr-namespace:TB4"
        xmlns:Converters="clr-namespace:WPF.Common.Converters;assembly=WPF.Common" Title="MainWindow" Height="431.159" Width="409.71">
    <Window.Resources>
        <Converters:ImageSourceToImageConverter x:Key="ImageSourceToImageConverter" />
        <Collections:ArrayList x:Key="Tools">
            <TB4:Tool Name="Select" ImageSource="Images\Mouse_pointer_or_cursor.png" Category="Category 1" />
            <TB4:Tool Name="Bucket" ImageSource="Images\Painting.png" Category="Category 1" />
            <TB4:Tool Name="Pen" ImageSource="Images\Pen.png" Category="Category 1" />
            <TB4:Tool Name="Move" ImageSource="Images\hand.png" Category="Category 2"/>
            <TB4:Tool Name="Brush" ImageSource="Images\brush.png" Category="Category 2" />
            <TB4:Tool Name="Chicken Tool" ImageSource="Images\splash-chick.png" Category="Category 3" />
        </Collections:ArrayList>
        <CollectionViewSource x:Key="CollectionViewSource" Source="{StaticResource Tools}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Category"/>
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>

    </Window.Resources>
    <Grid>
        <TB4:GroupToolbar x:Name="myTb" ItemsSource="{Binding Source={StaticResource CollectionViewSource}}" Margin="14.29,10,0,74" HorizontalAlignment="Left" Width="95.71">
            <TB4:GroupToolbar.ToolbarItemTemplate>
                <DataTemplate DataType="TB4:Tool">
                    <DockPanel>
                        <TextBlock DockPanel.Dock="Bottom" Text="{Binding Name}" />
                        <Image Width="30" Height="30" Source="{Binding ImageSource}" />
                    </DockPanel>
                </DataTemplate>
            </TB4:GroupToolbar.ToolbarItemTemplate>
            <TB4:GroupToolbar.SelectorContextMenuItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" />
                </DataTemplate>
            </TB4:GroupToolbar.SelectorContextMenuItemTemplate>

            <TB4:GroupToolbar.SelectorContextMenuItemContainerStyle>
                <Style TargetType="TB4:SelectorContextMenuItem">
                    <Setter Property="Icon" Value="{Binding ImageSource, Converter={StaticResource ImageSourceToImageConverter}}" />
                </Style>
            </TB4:GroupToolbar.SelectorContextMenuItemContainerStyle>
        </TB4:GroupToolbar>


        <!--<ContextMenu.ItemContainerStyle>
            <Style TargetType="MenuItem">
                <Setter Property="Icon" Value="{Binding ImageSource, Converter={StaticResource ImageSourceToImageConverter}}" />
            </Style>
        </ContextMenu.ItemContainerStyle>
        <ContextMenu.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Name}" />
            </DataTemplate>
        </ContextMenu.ItemTemplate>-->

        <ListBox ItemsSource="{Binding Source={StaticResource Tools}}" SelectedItem="{Binding ElementName=myTb, Path=SelectedItem, Mode=TwoWay}" Margin="192,10,0,122" HorizontalAlignment="Left" Width="197.71"></ListBox>
        <TextBlock HorizontalAlignment="Left" Margin="10,356,0,0" TextWrapping="Wrap" Text="{Binding SelectedItem, ElementName=myTb}" VerticalAlignment="Top" Height="34" Width="100"/>
        <ListBox Margin="194.355,283,12,0" ItemsSource="{Binding SelectedGroup.ItemsSource, ElementName=myTb}" VerticalAlignment="Top" Height="107"/>
    </Grid>
</Window>
